/*
package com.vf.admin.utils.pay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.vf.admin.utils.pay.ApiAliPay.AlipayConfig;
import com.vf.admin.utils.pay.ApiAplayWeChat.*;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

*/
/**
 * 支付接口（支付宝，微信）
 *//*

public class ApiPayUtils {
    */
/**
     * alipayClient只需要初始化一次，后续调用不同的API都可以使用同一个alipayClient对象。
     *//*

    private static volatile ApiPayUtils instance;
    private static volatile AlipayClient alipayClient;

    */
/**
     * GATEWAYURL: 支付宝网关："https://openapi.alipay.com/gateway.do"
     * APPID: 创建应用后生成
     * APP_PRIVATE_KEY:开发者私钥
     * FORMAT:参数返回格式  JSON
     * CHARSET:UTF-8
     * ALIPAY_PUBLIC_KEY:支付宝公钥，支付宝生成
     * SIGN_TYPE:签名算法类型 RSA2
     *//*

    private ApiPayUtils() {
        alipayClient = new DefaultAlipayClient(AlipayConfig.GATEWAYURL,
                AlipayConfig.APPID, AlipayConfig.APP_PRIVATE_KEY,
                AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY,
                AlipayConfig.SIGN_TYPE);
    }

    public static ApiPayUtils getInstance() {
        if (instance == null) {
            synchronized (ApiPayUtils.class) {
                if (instance == null) {
                    instance = new ApiPayUtils();
                }
            }
        }
        return instance;
    }

    */
/**
     * 调支付接口（支付宝）
     * @return
     * @throws Exception
     *//*

    public String apiTextAliPay(String title,String orderid,double jine)throws Exception{
        //以下为支付宝支付流程
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        AlipayTradeAppPayRequest ali_request = new AlipayTradeAppPayRequest();
        //SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody(title);//对一笔交易的具体描述信息。如果是多种商品，请将商品描述字符串累加传给body。
        model.setSubject(title);//商品名称
        model.setOutTradeNo(orderid);//商户订单号(自动生成)
        model.setTimeoutExpress("30m");//交易超时时间
        model.setTotalAmount(""+jine);//支付金额
        model.setProductCode("QUICK_MSECURITY_PAY");//销售产品码（固定值）
        ali_request.setBizModel(model);
        ali_request.setNotifyUrl(AlipayConfig.ali_notify_url);//异步回调地址（后台）
        // ali_request.setReturnUrl(AlipayConfig.RETURN_URL);//同步回调地址（APP）


        AlipayTradeAppPayResponse alipayTradeAppPayResponse = alipayClient.sdkExecute(ali_request); //返回支付宝订单信息(预处理)
        //orderString为返回值
        String orderString = alipayTradeAppPayResponse.getBody();

        return orderString;
    }


    */
/**
     * 支付宝回调接口
     * @param request
     * @return
     * @throws Exception
     *//*

    public String apiTextTokenUrl(HttpServletRequest request)throws Exception{
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String[]> requestParams = request.getParameterMap();
        System.out.println("成功调用回掉地址success");
        for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
            System.out.println("进入for循环的次数");
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
            }
            params.put(name, valueStr);
        }
        boolean sign = false;
        try {
            for (String s : params.keySet()) {
                System.out.println("key : " + s + " value : " + params.get(s));
            }
            signVerified = AlipaySignature.rsaCheckV1(params,
                    AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET,
                    AlipayConfig.SIGN_TYPE);

        } catch (AlipayApiException e) {
            e.printStackTrace();
            System.out.println("验证公钥时出现异常");
        }
        if (signVerified) {
            // 商户订单号
            String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
            // 支付宝交易号
            String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"), "UTF-8");
            // 交易状态
            String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"), "UTF-8");
            System.out.println("——————商户订单号" + out_trade_no);
            System.out.println("-----------支付宝交易号" + trade_no);
            System.out.println("-----------交易状态" + trade_status);
            if (trade_status.equals("TRADE_SUCCESS")) {
                */
/**
                 * 返回的状态是success，接下来可以：更改订单支付成功状态，设置支付信息，等等业务处理……
                 *//*


                System.out.println("success");

                return "success";
            } else {
                */
/**
                 *  fail（失败） 的业务处理：……
                 *//*

                System.out.println("fail");
                return "success";

            }
        }

        return "success";
    }


    */
/**
     * 微信支付
     * @return
     *//*

    public Map<String, String> apiWeChatPay(String title,String orderid,double jine,HttpServletRequest request)throws Exception{
        //支付金额，单位：分
        int wxjine = (new Double(jine*100)).intValue();
        //生成的随机字符串
        String nonce_str = StringUtils.getRandomStringByLength(32);
        //商品名称
        String body = title;
        //获取本机的ip地址
        String spbill_create_ip = IpUtils.getIpAddr(request);
        System.out.println("本机的ip地址" + spbill_create_ip);
        Map<String, String> packageParams = new HashMap<String, String>();
        packageParams.put("appid", WxPayConfig.appid);//appid
        packageParams.put("mch_id", WxPayConfig.mch_id);//商户号
        packageParams.put("nonce_str", nonce_str);//随机字符串
        packageParams.put("body", body);//商品名
        Date date=new Date();

        packageParams.put("out_trade_no", orderid);//商户订单号
        packageParams.put("total_fee", wxjine+"");//支付金额(单位：分)，这边需要转成字符串类型，否则后面的签名会失败
        packageParams.put("spbill_create_ip", spbill_create_ip);
        packageParams.put("notify_url", WxPayConfig.notify_url);//微信支付回调地址
        packageParams.put("trade_type", WxPayConfig.TRADETYPE);//交易类型 APP
        packageParams = PayUtil.paraFilter(packageParams);
        String prestr = PayUtil.createLinkString(packageParams); // 把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串
        System.out.println("数组排序***********" + prestr);
        //MD5运算生成签名，这里是第一次签名，用于调用统一下单接口
        String mysign = PayUtil.sign(prestr, WxPayConfig.key, "utf-8").toUpperCase();
        System.out.println("=======================第一次签名：" + mysign + "=====================");
        String xml = "<xml>" + "<appid>" + WxPayConfig.appid + "</appid>"
                + "<body><![CDATA[" + body + "]]></body>"
                + "<mch_id>" + WxPayConfig.mch_id + "</mch_id>"
                + "<nonce_str>" + nonce_str + "</nonce_str>"
                + "<notify_url>" + WxPayConfig.notify_url + "</notify_url>"
                //+ "<openid>" + aliPay.getOpenID() + "</openid>"
                + "<out_trade_no>" + orderid+"" + "</out_trade_no>"
                + "<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>"
                + "<total_fee>" + wxjine + "</total_fee>"
                + "<trade_type>" + WxPayConfig.TRADETYPE + "</trade_type>"
                + "<sign>" + mysign + "</sign>"
                + "</xml>";
        System.out.println("调试模式_统一下单接口 请求XML数据：" + xml);

        //调用统一下单接口，并接受返回的结果
        String result = PayUtil.httpRequest(WxPayConfig.pay_url, "POST", xml);

        System.out.println("调试模式_统一下单接口 返回XML数据：" + result);

        // 将解析结果存储在HashMap中
        Map map = PayUtil.doXMLParse(result);//异常逻辑代码

        String return_code = (String) map.get("return_code");//返回状态码

        //返回给移动端需要的参数
        Map<String, String> response = new HashMap<String, String>();
        if (return_code!=null && return_code.equals("SUCCESS")) {
            String prepay_id = (String) map.get("prepay_id");//返回的预付单信息
            response.put("appid", WxPayConfig.appid);
            response.put("noncestr", nonce_str);
            response.put("package", "Sign=WXPay");
            response.put("prepayid", prepay_id);
            Long timeStamp = System.currentTimeMillis() / 1000;
            response.put("timestamp", timeStamp + "");//这边要将返回的时间戳转化成字符串，不然小程序端调用wx.requestPayment方法会报签名错误
            response.put("partnerid", WxPayConfig.mch_id);
            //response.put("sign_type",WxPayConfig.SIGNTYPE);
            response = PayUtil.paraFilter(response);
            String prestrdd = PayUtil.createLinkString(response);
            System.out.println("二次签名数据" + prestrdd);
            //再次签名，这个签名用于APP端调用wx.requesetPayment方法
            String paySign = PayUtil.sign(prestrdd, WxPayConfig.key, "utf-8").toUpperCase();
            System.out.println("=======================第二次签名：" + paySign + "=====================");
            response.put("sign", paySign);
        }

        return response;
    }


    */
/**
     * 微信回调地址
     * @param request
     * @param response
     * @throws Exception
     *//*

    public void wxNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream()));
        String line = null;
        StringBuilder sb = new StringBuilder();
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        br.close();
        //sb为微信返回的xml
        String notityXml = sb.toString();
        String resXml = "";
        System.out.println("接收到的报文：" + notityXml);

        Map map = PayUtil.doXMLParse(notityXml);

        String returnCode = (String) map.get("return_code");
        System.out.println("接收到的报文 returnCode：" + returnCode);
        if ("SUCCESS".equals(returnCode)) {
            //验证签名是否正确
            SortedMap<String, String> packageParams = new TreeMap<String, String>();
            packageParams.put("appid", map.get("appid") != null ? map.get("appid").toString() : null);
            packageParams.put("attach", map.get("attach") != null ? map.get("attach").toString() : null);
            packageParams.put("bank_type", map.get("bank_type") != null ? map.get("bank_type").toString() : null);
            packageParams.put("cash_fee", map.get("cash_fee") != null ? map.get("cash_fee").toString() : null);
            packageParams.put("fee_type", map.get("fee_type") != null ? map.get("fee_type").toString() : null);
            packageParams.put("is_subscribe", map.get("is_subscribe") != null ? map.get("is_subscribe").toString() : null);
            packageParams.put("mch_id", map.get("mch_id") != null ? map.get("mch_id").toString() : null);
            packageParams.put("nonce_str", map.get("nonce_str") != null ? map.get("nonce_str").toString() : null);
            packageParams.put("openid", map.get("openid") != null ? map.get("openid").toString() : null);
            packageParams.put("out_trade_no", map.get("out_trade_no") != null ? map.get("out_trade_no").toString() : null);
            packageParams.put("result_code", map.get("result_code") != null ? map.get("result_code").toString() : null);
            packageParams.put("return_code", map.get("return_code") != null ? map.get("return_code").toString() : null);
            packageParams.put("time_end", map.get("time_end") != null ? map.get("time_end").toString() : null);
            packageParams.put("total_fee", map.get("total_fee") != null ? map.get("total_fee").toString() : null);
            packageParams.put("trade_type", map.get("trade_type") != null ? map.get("trade_type").toString() : null);
            packageParams.put("transaction_id", map.get("transaction_id") != null ? map.get("transaction_id").toString() : null);
            String sign = Signature.createSign(packageParams, WxPayConfig.key);

//	        	Map<String, String> validParams = PayUtil.paraFilter(map);  //回调验签时需要去除sign和空值参数
//	            String validStr = PayUtil.createLinkString(validParams);//把数组所有元素，按照“参数=参数值”的模式用“&amp;”字符拼接成字符串
//	            String sign = PayUtil.sign(validStr, WXConst.key, "utf-8").toUpperCase();//拼装生成服务器端验证的签名
            // 请求物流接口信息
            System.out.println("根据参数本地签名 sign：" + sign + "   微信返回的签名：" + map.get("sign"));
            //根据微信官网的介绍，对回调的参数进行验签
            if (sign.equals(map.get("sign"))) {
                */
/**此处添加自己的业务逻辑代码start**//*

                System.out.println("验证签名成功" + map.get("out_trade_no"));
                String orderNum = (String) map.get("out_trade_no");


                */
/**此处添加自己的业务逻辑代码end**//*


                //通知微信服务器已经支付成功
                resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
                        + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";


            } else {
                resXml = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>"
                        + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
            }
        } else {
            resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>"
                    + "<return_msg><![CDATA[报文为空]]></return_msg>" + "</xml> ";
        }
        System.out.println(resXml);
        System.out.println("微信支付回调数据结束");

        BufferedOutputStream out = new BufferedOutputStream(
                response.getOutputStream());
        out.write(resXml.getBytes());
        out.flush();
        out.close();
    }


















}
*/
